package java7;

import java.io.*;

/**
 * @author draem
 * @create 2018-06-19 22:44
 */
public class TryWithResourcesTest {

    public static void main(String[] args) throws IOException {
        //

        TryWithResourcesTest tt=new TryWithResourcesTest();
        String root =tt.getRoot();
        String fromPath =root+"/main/resources/a.txt";
        String toPath =root+"/main/resources/b.txt";

        tt.copyFile(fromPath,toPath);
    }
    public String  getRoot(){
        System.out.println(TryWithResourcesTest.class .getResource("")      );
       return this.getClass().getResource("/").getPath();

    }

    public static  void copyFile(String fromPath, String toPath) throws IOException {
        try (InputStream  input = new FileInputStream(fromPath);
             OutputStream output = new FileOutputStream(toPath) ) {
            byte[] buffer = new byte[8192];
            int len = -1;
            while( (len=input.read(buffer))!=-1 ) {
                output.write(buffer, 0, len);
            }
        }
    }
}
